{extends file="../acp.html"}

{block name="title"}{$head_title}{/block}
{block name="content"}
<div class="tablesWrap">  
<div class="tables-searchbox">
    <form name="search_form" id="search_form" method="POST" action="">
            <div class="apiece"><span>优惠券名称：</span><input type="text" placeholder="" class="small" name="coupon_name" id="order_sn" value="{$coupon_name}"> </div>

            <div class="apiece"><span>使用状态：</span>
                <select class="small" name="apply_state" id="apply_state">
                    <option value="-1">-全部-</option>
                    <option value="0" {if isset($state) && $state == 0}selected{/if}>未使用</option>
                    <option value="1" {if isset($state) && $state == 1}selected{/if}>已使用</option>
                    <option value="2" {if isset($state) && $state == 2}selected{/if}>已过期</option>
                </select>
            </div>

            <div class="apiece"><span>用户：</span><input type="text" placeholder="" class="large" name="user_name" id="user_name" value="{$user_name}"> </div>

            <div class="t-pay-time-ri"><button type="submit" class="btn"><i class="gicon-search"></i>搜索</button> </div>
    </form>
</div>  
<!-- end tables-searchbox -->  
<table class="wxtables">  
    <!--
    <colgroup>  
    <col width="10%">
    <col width="20%">
    <col width="10%">
    <col width="20%">
    <col width="20%">
    <col width="20%">
    </colgroup>
    -->
    <thead>
        <tr>  
            <td>选择</td>  
            <td>优惠券名称</td>
            <td>优惠券金额</td>
            <td>用户</td>.
            <td>使用金额（限制）</td>
            <td>是否可用</td>
            <td>是否使用</td>
            <td>获得时间</td>
            <td>订单编码</td>
            <td>操作</td>
        </tr>  
    </thead>  
    {foreach from=$coupon_list item=coupon}
    <tbody class="combo-tbody">  
        <tr>
			<td><input type="checkbox" class="checkbox" name="a[]" value="{$coupon.coupon_id}"></td>
            <td>{$coupon.coupon_name}</td>
            <td>{$coupon.num}</td>
            <td>{$coupon.realname}</td>
            <td>订单额需>{$coupon.price_limit}</td>
            <td>{$coupon.usable}</td>
            <td>{$coupon.state_name}</td>
            <td>{$coupon.addtime|date_format:"%Y-%m-%d %H:%M:%S"}</td>
            <td>{$coupon.order_sn}</td>
            <td>  
                <!--   <a href="/AcpPromo/edit_coupon/coupon_id/{$coupon.coupon_id}" class="btn" title="修改">修改</a>  -->
                <a href="javascript:;" class="btn" title="删除" onclick="delete_question_class({$coupon.coupon_id})">删除</a>  
            </td>  
        </tr>
    </tbody>
	{foreachelse}   
    <tbody>    
		<tr>
			<td colspan="7">
				没有符合条件的记录
			</td>
		<tr>
    </tbody>  
	{/foreach}
</table>  
<!-- end wxtables -->  
<div class="tables-btmctrl clearfix">  
    <div class="fl">  
        <a href="javascript:;" class="btn btn-blue" onclick="Select()">全选</a>  
        <a href="javascript:;" class="btn btn-blue" onclick="Cancel()">取消</a>  
        <a href="javascript:;" onclick="batch_delete()" class="btn btn-blue">删除</a>
    </div>  
    <div class="fr">  
        <div class="paginate">
			{$page_str} 
        </div>  
        <!-- end paginate -->  
    </div>  
</div>  
<!-- end tables-btmctrl -->  
</div>  
<!-- end tablesWrap -->   
{/block} 

{block name="js"}
<script src="/Public/Plugins/My97DatePicker/WdatePicker.js?version={$version}"></script>
{literal}
<script>
	//全选
	function Select(){
		var sel=document.getElementsByName("a[]");
		for(var i=0;i<sel.length;i++){
			sel[i].checked=true;
		}
	}
	//取消全选
	function Cancel(){
		var sel=document.getElementsByName("a[]");
		for(var i=0;i<sel.length;i++){
			sel[i].checked=false;
		}
	}

function delete_question_class(question_class_id)
{
	$.jPops.confirm(
	{  
		 title:"提示",  
		 content:"您确定要删除这条数据吗？",  
		 okBtnTxt:"确定",  
		 cancelBtnTxt:"取消",  
		 callback:function(r)
		 {  
			 if(r)
			 {
				 $.post('/AcpPromo/del_coupon', {"id":question_class_id}, function(data, textStatus) 
				 {
					if (data == 'success')
					{
						alert('恭喜您，删除成功！');
						location.reload();
					}
					else
					{
						alert('对不起，删除失败！');
					}
				});
			 }  
			 return true;  
		 }
	 });  	
}

function batch_delete()
{
	$.jPops.confirm(
	{  
		 title:"提示",  
		 content:"您确定要删除这些数据吗？",  
		 okBtnTxt:"确定",  
		 cancelBtnTxt:"取消",  
		 callback:function(r)
		 {  
			 if(r)
			 {
				 var question_class_ids = '';
				 var count = 0;
				 $('input[name="a[]"]:checked').each(function(){
					 count ++;
					 question_class_ids += $(this).val() + ',';
				 });

				 if (!count)
				 {
					 alert('对不起，请选择至少一项进行删除！');
					 return;
				 }

				 question_class_ids = question_class_ids.substr(0, question_class_ids.length - 1);

				 $.post('/AcpPromo/batch_delete_coupon', {"ids":question_class_ids}, function(data, textStatus) 
				 {
					if (data == 'success')
					{
						alert('恭喜您，删除成功！');
						location.reload();
					}
					else
					{
						alert('对不起，删除失败！');
					}
				});
			 }  
			 return true;  
		 }
	 });
}
</script>
{/literal}
{/block} 

{block name="css"}
<link type="text/css" rel="stylesheet" href="__ACPCSS__/tip.css" />
{literal}
<style>
.PageNext{page-break-after: always; height:1px;}
</style>
{/literal}
{/block} 
